package com.mvc.util;

import java.lang.reflect.Field;

import javax.servlet.http.HttpServletRequest;

public class FullForm {
	public static Form full(String formtype, HttpServletRequest request) {
		Form form = null;
		try {
			Class<?> clazz = Class.forName(formtype);
			form = (Form) clazz.newInstance();
			Field[] f = clazz.getDeclaredFields();
			for (Field field : f) {
				field.setAccessible(true);
				Class fieldclass = field.getType();
				String requestvalue = request.getParameter(field.getName());
				Object fieldvalue = requestvalue;
				if (fieldclass.getName().equals("int")) {
					fieldvalue = Integer.parseInt(requestvalue);
				}
				field.set(form, fieldvalue);
				field.setAccessible(false);
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}

		return form;
	}
}
